//
//  Synchronization+Contacts.m
//  exSync
//
//  Created by Alexander Chaika on 31.01.12.
//  Copyright 2012 by Alexander Chaika. All rights reserved.
//

#import "resource.h"

#import "Synchronization+Contacts.h"

@implementation Synchronization (Contacts)

- (void)updateContactsSyncScheduleWithInterval:(int)interval {
	self.contactsNextSync = nil;
	if ([[NSUserDefaults standardUserDefaults] boolForKey:kSyncStarted] &&
		[[NSUserDefaults standardUserDefaults] boolForKey:kSyncContacts] &&
		interval >= 0)
		self.contactsNextSync = [NSDate dateWithTimeIntervalSinceNow:interval];
}

- (void)syncContacts {
	if (!accessToken) // need access token to do sync
		return;
	
	if (contactsState < 0) {
		// check sync contacts flag
		if (![[NSUserDefaults standardUserDefaults] boolForKey:kSyncContacts])
			return;
	
		// check for sync time
		if (!contactsNextSync || [contactsNextSync timeIntervalSinceNow] > 0.)
			return;
		
		contactsState = 0;
	}

	// states
	switch (contactsState) {
		case 0: // get deleted contacts from server
			break;
			
		case 1: // get new or updated contacts from server
			break;
	}
	
	//	
	//	// create request
	//	NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com/m8/feeds/contacts/default/full"]] autorelease];
	//	[request setValue:[NSString stringWithFormat:@"Bearer %@", accessToken] forHTTPHeaderField:@"Authorization"];
	//	[request setValue:@"3.0" forHTTPHeaderField:@"GData-Version"];
	//
	//	// create connection
	//	if ((curConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self])) {
	//		receivedData = [[NSMutableData alloc] init];
	//		operationInProgress = 100;
	//	}
	//	
}

@end
